import Vue from 'vue'
import { USER_INFO, ENHANCE_PRE } from "@/store/mutation-types"
const getters = {
  device: state => state.app.device,
  theme: state => state.app.theme,
  color: state => state.app.color,
  token: state => state.user.token,
  avatar: state => {state.user.avatar = Vue.ls.get(USER_INFO).avatar; return state.user.avatar},
  username: state => state.user.username,
  nickname: state => {state.user.realname = Vue.ls.get(USER_INFO).realname; return state.user.realname},
  welcome: state => state.user.welcome,
  permissionList: state => state.user.permissionList,
  userInfo: state => {state.user.info = Vue.ls.get(USER_INFO); return state.user.info},
  addRouters: state => state.permission.addRouters,
  onlAuthFields: state => {return state.online.authFields },
  enhanceJs:(state) => (code) => {
    state.enhance.enhanceJs[code] = Vue.ls.get(ENHANCE_PRE+code);
    return state.enhance.enhanceJs[code]
  },
  menuData(state) {
    return state.user.permissionList
  },
  firstMenu(state) {
    let menuData = state.user.permissionList

    return menuData.map(item => {
      let menuItem = {...item}
      delete menuItem.children
      return menuItem
    })
  },
  subMenu(state) {
    let menuData = state.user.permissionList
    let activatedFirst = state.app.activatedFirst
    let current = menuData.find(menu => menu.path === activatedFirst)
    return current && current.children || []
  },
  systemName: state => state.app.systemName,
  animate: state => state.app.animate,
  animates: state => state.app.animates,
  showSide: state => state.app.showSide,
  fixedHeader: state => state.app.fixedHeader,
  layout: state => state.app.layout

}

export default getters
